﻿using System.ComponentModel;
using System.Runtime.CompilerServices;
using Acr.XamForms.UserDialogs;
using LiveMakkah.Pages;
using LiveMakkah.Utils;
using Xamarin.Forms;

namespace LiveMakkah.ViewModels
{
    public class BaseViewModel : INotifyPropertyChanged
    {
        private IUserDialogService _dialogs;



        protected BaseViewModel()
        {
            Dialogs=DependencyService.Get<IUserDialogService>();

            MessagingCenter.Subscribe<BasePage, string>(this, "LifeCycle", (sender, arg) =>
            {
                if (arg.Equals("OnAppearing"))
                {
                    OnAppearing();
                }
           
            });
        }

        public virtual void OnAppearing()
        {
      
        }


        public IUserDialogService Dialogs
        {
            get { return _dialogs; }
            set
            {
                _dialogs = value;
                OnPropertyChanged();
            }
            
        }

        public ViewModelNavigation Navigation
        {
            get; set; 
            
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}